package cn.acac.yygh.hosp.controller.api;

import cn.acac.yygh.hosp.result.Result;
import cn.acac.yygh.hosp.service.ScheduleService;
import cn.acac.yygh.hosp.utils.HttpRequestHelper;
import cn.acac.yygh.model.hosp.Schedule;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/hosp")
@Api("计划表的相关操作")
public class ApiScheduleController {

    @Autowired
    private ScheduleService scheduleService;

    /**
     * 根据id删除排班信息
     * @param request
     * @return
     */
    @PostMapping("/schedule/remove")
    public Result remove(HttpServletRequest request){
        Map<String, Object> switchMap = HttpRequestHelper.switchMap(request.getParameterMap());
        scheduleService.remove(switchMap);
        return Result.ok();
    }

    /**
     * 分页信息查询并返回
     * @param request
     * @return
     */
    @PostMapping("/schedule/list")
    public Result<Page> listPage(HttpServletRequest request){
        Map<String, Object> switchMap = HttpRequestHelper.switchMap(request.getParameterMap());
        Page<Schedule> schedulePage = scheduleService.listPage(switchMap);
        return Result.ok(schedulePage);
    }

    /**
     * 保存第三方医院的排班信息
     * @param request
     * @return
     */
    @PostMapping("/saveSchedule")
    public Result saveSchedule(HttpServletRequest request){
        Map<String, Object> switchMap = HttpRequestHelper.switchMap(request.getParameterMap());
        // sign的验证
        // 调用业务层保存第三方医院的信息
        scheduleService.saveAndUpdate(switchMap);
        return Result.ok();
    }
}
